package com.shareware.common.memory.entity

import com.shareware.common.utils.safeLet
import org.json.JSONObject

/**
 * desc: 功能描述
 * email: mobiledeveloper@qq.com
 */
class MemInfo(
    var processInfo: ProcessInfo? = ProcessInfo(),
    var statusInfo: StatusInfo? = StatusInfo(),
    var javaMemInfo: JavaMemInfo? = JavaMemInfo(),
    var nativeMemInfo: NativeMemInfo? = NativeMemInfo(),
    var systemInfo: SystemInfo? = SystemInfo.get(),
    var amsPssInfo: PssInfo? = null,
    var debugPssInfo: PssInfo? = null,
    var fgServiceInfo: FgServiceInfo? = FgServiceInfo(),
) {
    var cost = 0L
    override fun toString(): String {
        return """
                |> Process   : $processInfo
                |> Status    : $statusInfo
                |> SystemInfo: $systemInfo
                |> Java      : $javaMemInfo
                |> Native    : $nativeMemInfo
                |> Dbg-Pss   : $debugPssInfo
                |> AMS-Pss   : $amsPssInfo
                |> FgService : $fgServiceInfo
                | cost : $cost
            """.trimIndent()
    }

    fun toJson() = safeLet(defVal = JSONObject()) {
        JSONObject().apply {
            processInfo?.let { put("processInfo", it.toJson()) }
            statusInfo?.let { put("statusInfo", it.toJson()) }
            javaMemInfo?.let { put("javaMemInfo", it.toJson()) }
            nativeMemInfo?.let { put("nativeMemInfo", it.toJson()) }
            systemInfo?.let { put("systemInfo", it.toJson()) }
            amsPssInfo?.let { put("amsPssInfo", it.toJson()) }
            debugPssInfo?.let { put("debugPssInfo", it.toJson()) }
        }
    }
}